package com.wu.server.dao;

import com.wu.server.entity.Goods;
import org.springframework.data.annotation.QueryAnnotation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Wugs
 * @version 1.0
 * @date 2021/2/26 22:03
 */
@Repository
public interface GoodsRepository extends CrudRepository<Goods, Integer> {
    /**
     * // TODO: 2021/3/3 通过type标签查询goods 相似内容数量
     * @param type_name = title like
     * @return goods数量
     */
    @Query(value="select count(*)  from jd_shop.goods where title like ?1", nativeQuery = true)
    int SumType(String type_name);

    /**
     * // TODO: 2021/3/4 根据店铺相似名称查询数量（作用自营）
     * @param str
     * @return
     */
    @Query(value="select count(*)  from jd_shop.goods where shop_name like ?1",nativeQuery=true)
    int sumSelf(String str);
    /**
     * // TODO: 2021/3/3 通过type标签查询goods
     * @param type_name = title like
     * @return goods列表
     */
    @Query(value="select * from jd_shop.goods where title like ?1", nativeQuery = true)
    Iterable<Goods> goodsList(String type_name);

    /**
     * // TODO: 2021/3/6 获取商品数量最大值
     * @return
     */
    @Query(value="select max(prince) from jd_shop.goods",nativeQuery=true)
    int goodsMax();


    /**
     * 根据商品价格区间获取商品数量
     * @return 商品数量
     */
    @Query(value="select *  from jd_shop.goods where prince between ?1 and ?2",nativeQuery = true)
    Iterable<Goods> getGoodsByPrinceBetween(Integer start,Integer end);

    /**
     * 获取根据商品销量排序的商品列表
     * @return
     */
    @Query(value="select *  from jd_shop.goods order by sales desc limit 100;",nativeQuery = true)
    Iterable<Goods> getSalesOrder();

    /**
     * 获取所有商品店铺名称
     * @return
     */
    @Query(value="select distinct shop_name from jd_shop.goods;",nativeQuery = true)
    Iterable<String> getShopNameList();

    @Query(value="select * from goods where shop_name = ?1",nativeQuery = true)
    Iterable<Goods> getShop(String shop_name);

    /**
     * // TODO: 2021/3/6 根据标签查询商品的数量
     * @param tag_name
     * @return
     */
    @Query(value="select sales from jd_shop.goods where tag_name like ?1", nativeQuery = true)
    Iterable<Integer> getTagSummary(String tag_name);
    @Query(value="select count(*) from jd_shop.goods where tag_name like ?1", nativeQuery = true)
    int getTagCount(String tag_name);
}
